//编写一个程序,打印输入中各个字符出现频度的直方图
#include <stdio.h>
#include <ctype.h>
#define MAXCHAR 128
#define MAXHIST 20

int main()
{
    int c, i, len;
    int cc[MAXCHAR];                            //统计各字符次数的数组
    int maxvalue;                               //字符次数最大值

    for (i = 0; i < MAXCHAR; ++i)
        cc[i] = 0;
    maxvalue = -1;

    //计数
    while ((c = getchar()) != EOF)
        if (c < MAXCHAR)
            ++cc[c];
    //得到频次最大值
    for (i = 0; i < MAXCHAR; ++i)
    {
        if (cc[i] > maxvalue)
            maxvalue = cc[i];
    }
    //打印水平直方图
    //打印水平方向直方图
    for (i = 0; i < MAXCHAR; ++i)
    {
        len = cc[i];
        if (isprint(i))
            printf("%5d - %c - %5d", i, i, cc[i]);
        else
            printf("%5d -   - %5d", i, cc[i]);
        if (cc[i] > 0)
        {
            if ((len = cc[i] * MAXHIST / maxvalue) <= 0)
                len = 1;
            else
                len = 0;
        }
        while (len > 0)
        {
            putchar('*');
            --len;
        }
        printf("\n");
    }
    return 0;
}